classdef RankingSupportVectorMachine ...
        < MultiLabelAlgorithm ...
        & MultiLabelMetricable ...
        & Modelable
    %RANKINGSUPPORTVECTORMACHINE Summary of this class goes here
    %   Detailed explanation goes here
    
    properties ( SetAccess = protected )
        svmType = 'linear' % enum{'linear', 'poly', 'rbf'}
        svmPara = []; % `= []` for 'linear' kernel; ...
                      % = [gamma, coefficient, degree] for 'poly' kernel;
                      % = gamma for 'rbf' kernel
        cost = 1
        lambdaTolerance = 1e-6
        normTolerance = 1e-4
        maximumIteration = 50
    end
    
    methods
        function [  ] = setSvmType( this, svmType )
            if nargin == 1
                this.svmType = 'linear';
            end
            if nargin == 2
                this.svmType = svmType;
            end
        end
        
        function [  ] = setSvmPara( this, svmPara )
            if nargin == 1
                this.svmPara = [];
            end
            if nargin == 2
                this.svmPara = svmPara;
            end
        end
        
        function [  ] = setCost( this, cost )
            if nargin == 1
                this.cost = 1;
            end
            if nargin == 2
                this.cost = cost;
            end
        end
        
        function [  ] = setLambdaTolerance( this, lambdaTolerance )
            if nargin == 1
                this.lambdaTolerance = 1e-6;
            end
            if nargin == 2
                this.lambdaTolerance = lambdaTolerance;
            end
        end
        
        function [  ] = setNormTolerance( this, normTolerance )
            if nargin == 1
                this.normTolerance = 1e-4;
            end
            if nargin == 2
                this.normTolerance = normTolerance;
            end
        end
        
        function [  ] = setMaximumIteration( this, maximumIteration )
            if nargin == 1
                this.maximumIteration = 50;
            end
            if nargin == 2
                this.maximumIteration = maximumIteration;
            end
        end
    end
    
    methods
        function [ this ] = RankingSupportVectorMachine( name )
            if nargin == 0
                this.setName('rank_svm');
            end
            if nargin >= 1
                this.setName(name);
            end
        end
    end
    
    methods
        function [  ] = build( this, X1, Y1 )
            this.model = buildRankSVM(X1, Y1, ...
                this.svmType, this.svmPara, this.cost, ...
                this.lambdaTolerance, this.normTolerance, ...
                this.maximumIteration);
        end
        
        function [ result ] = apply( this, X2, Y2 )
            result = applyRankSVM(X2, Y2, this.model);
        end
    end
end

